<?php
/**
 * 会员相关接口
 */
require_once APP_PATH.'/member/global.php';
class member_util_interface{
	
	
	/**
	 * 用户浏览漫画记录
	 *
	 * @param unknown_type $cartoon_id
	 * @param unknown_type $uid
	 * @param unknown_type $chapter_id
	 */
	public function readLog($cartoon_id,$uid,$chapter_id){
		return Model::factory("cartoon_model_data")->readLog($cartoon_id,$uid,$chapter_id);
	}
	
	
	/**
	 * 搜索会员
	 * @param unknown_type $k	搜索关键词
	 * @param unknown_type $page 页码
	 * @param unknown_type $pageSize 每页显示数量
	 */
	public function search($k,$page = 1,$pageSize = 16,$exclude = false){
		if($k){
			if(is_numeric($k)){
				$args['uid']	=	(int) $k;
			}
			elseif(checkEmail($k)){
				$args['email']	=	$k;
			}
			else{
				$args['username']	=	$k;
			}
		}
		
		return Model::factory('member_model_data')->search($args,$page,$pageSize,$exclude);
	}
	
	public static  function getUserCount($uid,$flush = false){
		return Model::factory('member_model_data')->getCountByUid($uid,$flush);
	}
	/**
	 * 发送邮件
	 *
	 * @param unknown_type $to
	 * @param unknown_type $subject
	 * @param unknown_type $contents
	 */
	public function sendMail($to,$subject,$contents){
		date_default_timezone_set("Asia/Shanghai");//设定时区东八区		
		if(!checkEmail($to)) return false; //检查邮件格式
		$mail  = new PHPMailer(); //new一个PHPMailer对象出来
		$mail->IsHTML(true);//设置为html
		
		if(EMAIL_TYPE == 'smtp'){
			$mail->IsSMTP(); // 设定使用SMTP服务
			$mail->Host 	  =	MAIL_HOST;		
			$mail->Port       = 25;                   // SMTP服务器的端口号
    		$mail->Username   = MAIL_USER;  		// SMTP服务器用户名
    		$mail->From		  =	MAIL_USER;
    		$mail->FromName	  = '漫画国际客服';
    		$mail->Password   = MAIL_PWD;   // SMTP服务器密码 		
		}else{
			$mail->IsMail();
		}
		$mail->SMTPAuth = true;		
		
		$mail->AddAddress($to);
		
		$mail->Subject = $subject;
		
		$mail->Body = eregi_replace("[\]",'',$contents);
		
		return $mail->Send();
		
	}
	
	/**
 	 * 生成key
 	 *
 	 * @return unknown
 	*/
	function genKey(){
		$arg_num = func_num_args();//获取参数个数
		if($arg_num>0){
			$arg_list = func_get_args();
			array_push($arg_list,SECRET_KEY);
			$arg_list	=	func_get_args();
			$arg_list = implode('|',$arg_list);
			return md5($arg_list);
		}
		return false;
	}
	
	/**
     * @desc  获取用户的性别
     * @param  $uid
     * @return string
     */
    static function getUserGender($uid){
		$row = member_util_login::getMemberInfo($uid);
		return ($row['gender_flag']==MEMBER_MALE)?'男':
			($row['gender_flag']==MEMBER_FEMALE?'女':'未知');
	}
	
	/**
	 * 加密字符串
	 *
	 * @param unknown_type $email
	 */
	public static function enCode($email){
		$SL = SecureLogin::getInstance();
		return  $SL->encode_email($email,time());
	}
	
	/**
	 * 解密邮箱
	 *
	 * @param unknown_type $str
	 * @return unknown
	 */
	public static function deCode($str){
		$SL = SecureLogin::getInstance();
		return $SL->decode_email($str);
	}

}